package com.hencoder.hencoderpracticedraw1.practice;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Build;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

public class Practice11PieChartView extends View {

    private Paint mPaint;

    public Practice11PieChartView(Context context) {
        super(context);
    }

    public Practice11PieChartView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
    }

    public Practice11PieChartView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

//        综合练习
//        练习内容：使用各种 Canvas.drawXXX() 方法画饼图
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mPaint.setColor(Color.RED);
            canvas.drawArc(100,45,500,445,-180,120,true,mPaint);

            mPaint.setColor(Color.WHITE);
            canvas.drawLine(120,50,200,50,mPaint);
            canvas.drawLine(200,50,220,60,mPaint);
            mPaint.setTextSize(20);
            mPaint.setColor(Color.WHITE);
            canvas.drawText("Lollipop",40,55,mPaint);

            mPaint.setColor(Color.YELLOW);
            canvas.drawArc(110,55,510,455,-60,58,true,mPaint);
            mPaint.setColor(Color.GREEN);
            canvas.drawArc(110,55,510,455,0,10,true,mPaint);
            mPaint.setColor(Color.GRAY);
            canvas.drawArc(110,55,510,455,12,7,true,mPaint);
            mPaint.setColor(Color.CYAN);
            canvas.drawArc(110,55,510,455,21,50,true,mPaint);
            mPaint.setColor(Color.LTGRAY);
            canvas.drawArc(110,55,510,455,73,102,true,mPaint);
        }

    }
}
